using System;
using UnityEngine;
using System.Collections.Generic;
using CommonFactory;
using CharacterSystem;

public class HeroInfo:ScriptableObject,IDataCollectionTemplete
{
    public List<HeroData>  Data = new List<HeroData>();
    /// <summary>
    /// 获得内容Type
    /// </summary>
    public Type GetContenType()
    {
        return typeof(HeroData);
    }
    /// <summary>
    /// 通过ID获取数据
    /// </summary>
    public HeroData GetDataByID(int id)
    {
        for(int i=0;i < Data.Count;i++)
        {
             if(Data[i].ID==id)
             {
                return Data[i];
             }
        }
        return null;
    }
    /// <summary>
    /// 转换成当前内容类型的列表
    /// </summary>
    public void ConvertToContentList(List<IDataTemplete> contents)
    {
       for(int i = 0; i < contents.Count; i++)
       {
           Data.Add((HeroData)contents[i]);
       }
    }
}


[Serializable]
public class HeroData : IDataTemplete , ICommonProductData, ICharacterData
{
    /// <summary>
    /// 索引号
    /// </summary>
    public int ID ;
    /// <summary>
    /// 名称
    /// </summary>
    public string Name ;
    /// <summary>
    /// 职业（1:战士2:法师3:枪手4:骑士5.牧师）
    /// </summary>
    public int Profession ;
    /// <summary>
    /// 技能
    /// </summary>
    public List<int> Skills ;
    /// <summary>
    /// 头像
    /// </summary>
    public string Icon ;
    /// <summary>
    /// 路径
    /// </summary>
    public string ResName ;
    /// <summary>
    /// 是否为空
    /// </summary>
    public bool IsEmpty { get; set; }
    /// <summary>
    /// 资源地址
    /// </summary>
    public string ResPath { get{ return ResName; } }
    /// <summary>
    /// 构造方法
    /// </summary>
    public HeroData()
    {
        IsEmpty = true;
        ID= default(int);
        Name= default(string);
        Profession= default(int);
        Skills= new List<int>();
        Icon= default(string);
        ResName= default(string);
    }
    /// <summary>
    /// 反序列化
    /// </summary>
    public void DeSerialize(object[] content)
    {
        ID = string.IsNullOrEmpty(content[0].ToString()) ? 0 : Int32.Parse(content[0].ToString());
        Name = content[1].ToString();
        Profession = string.IsNullOrEmpty(content[2].ToString()) ? 0 : Int32.Parse(content[2].ToString());
        Skills = string.IsNullOrEmpty(content[3].ToString()) ?  new List<int>() : ConvertUtils.GetIntListByString(content[3].ToString());
        Icon = content[4].ToString();
        ResName = content[5].ToString();
        for(int i = 0 ;i < content.Length ; i++ )
        {
             if(content[i] != null)
             {
                 IsEmpty = false;
             }
        }
    }
}